﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ball : MonoBehaviour {
	protected float jump_speed = 6f;
	private Rigidbody rd; 
	bool isjump = false;
	// Use this for initialization
	void Start () {        
		rd = GetComponent<Rigidbody>();	
	}	
	// Update is called once per frame
	void Update()
	{
		int force = 3;
		float h = Input.GetAxis("Horizontal");        
		float v = Input.GetAxis("Vertical");        
		rd.AddForce(new Vector3(h, 0, v)*force);
		if(Input.GetKeyDown("space"))
		{
			if(!isjump){
				GetComponent<Rigidbody>().velocity = Vector3.up * jump_speed;
				isjump = true;
			}
		}
	}
	void OnCollisionEnter(Collision collision)
	{       
		if (collision.collider.tag == "ground")//跳跃判定          
		{            
			isjump = false;     
		} 
		if (collision.collider.tag == "otherone")          
		{            
			this.gameObject.SetActive(false); 
			GUI.Label( new Rect( Screen.width * 0.5f , Screen.height * 0.5 , 100, 30) , "叫我红领巾！" );
		} 
		if (collision.collider.tag == "false")//碰撞的是fasle失败          
		{            
			this.gameObject.SetActive(false); 
		} 
	}
}
